import { defineConfig } from 'vite'
import path from 'path'
import proxys from './config/proxys'
import vueJsx from '@vitejs/plugin-vue-jsx'
import checker from 'vite-plugin-checker'
import ElementPlus from 'unplugin-element-plus/vite'

const { resolve } = path
const pathSrc = resolve(__dirname, 'src')

// https://vitejs.dev/config/
export default defineConfig((configEnv) => {
  return {
    plugins: [
      vueJsx(),
      ElementPlus({
        useSource: true
      }),
      checker({
        typescript: true,
        vueTsc: false,
        eslint: {
          lintCommand: 'eslint "./src/**/*.{ts,tsx}"' // for example, lint .ts & .tsx
        }
      })
    ],
    resolve: {
      extensions: ['.js', '.ts', '.jsx', '.tsx'],
      alias: {
        '~': pathSrc
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: "@use '~/globalVariable.scss' as *;"
        }
      }
    },
    server: {
      host: true,
      proxy: proxys[configEnv.mode]
    },
    build: {
      minify: 'terser',
      brotliSize: false,
      sourcemap: false,
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true
        },
        keep_fnames: true
      }
    }
  }
})
